class ArchiveController < ApplicationController
  # Lists the 42 most recent photographs uploaded by the user to Flickr
  def index
    @gallery = Gallery.instance
    @photos = @gallery.flickr.people.getPublicPhotos(LIGHTBOX_CONFIG[:flickr_user_id],nil,42,1)
    @header = 'Recent Photos'
  end
  # Searches Flickr to fetch a list of photographs matching the search terms entered.
  # Search is restricted to the photos uploaded by the user and is tag based.
  # If multiple tags are entered (separated by spaces) then the search is done considering the two tags
  # as a boolean AND.
  def search
    @gallery = Gallery.instance
    @search = params[:search].strip.gsub(" ",",")
    @photos = @gallery.flickr.photos.search(LIGHTBOX_CONFIG[:flickr_user_id],@search,
                                             'all',nil,nil,nil,nil,nil,nil,nil,500,nil,'date-posted-asc')
    if !@photos.nil?
      @header = 'Search Results'
      @search = @search.gsub(","," ")
      render(:template => "archive/index")
    else
      redirect_to(:action => 'index')
    end
  end
end
